<include file="header" />
<body>
<div class="wraper">
    <div class="header">
        <div class="title text-center font-16">一卡通支付</div>
    </div>
    <div class="classify content margin-t12">
        <div class="content-list flex">
            <div class="user-hint">姓名</div>
            <div class="input">
                <input id="username" type="text" />
            </div>
        </div>
        <div class="content-list flex">
            <div class="user-hint">一卡通账号</div>
            <div class="input">
                <input id="account" type="password" />
            </div>
        </div>
        <div class="content-list flex">
            <div class="user-hint">密码</div>
            <div class="input">
                <input id="password" type="password" />
            </div>
        </div>
    </div>
    <!--<div class="classify content margin-t12">
        <div class="content-list flex">
            <div class="user-hint">手机号码</div>
            <div class="input">
                <input id="mobile" <notempty name="card['mobile']">value="{BEESCRM:$card['mobile']}"</notempty>  type="text" placeholder="请填写手机号码">
            </div>
            <a href="#" class="blue send show font-12">获取验证码</a>
        </div>
        <div class="content-list flex">
            <div class="user-hint">验证码</div>
            <div class="input">
                <input type="text" id="code" placeholder="请填写验证码">
            </div>
        </div>
    </div>-->
    <input type="hidden" id="restaurant_id" value="{BEESCRM:$restaurantId}">
    <input type="hidden" id="res_id" value="{BEESCRM:$resId}">
    <input type="hidden" id="iPad_id" value="{BEESCRM:$iPadId}">
    <input type="hidden" id="order_id" value="{BEESCRM:$orderId}">
    <div class="btn-box">
        <form id="form_campuscard" method="post" action="">
            <input type="hidden" name="tranamt" value="" /><!--交易金额1-->
            <input type="hidden" name="account" value="" /><!--学生账号-->
            <input type="hidden" name="sno" value="" /><!--学工号-->
            <input type="hidden" name="toaccount" value="" /><!--商户账号1-->
            <input type="hidden" name="thirdsystem" value="" /><!--系统注册ID1-->
            <input type="hidden" name="thirdorderid" value="" /><!--第三方订单号1-->
            <input type="hidden" name="ordertype" value="" /><!--接入类型1-->
            <input type="hidden" name="sign" value="" /><!--sign签名-->
            <input type="hidden" name="orderdesc" value="" /><!--商品名称-->
            <input type="hidden" name="praram1" value="" /><!--第三方系统备注字段-->
            <input type="hidden" name="thirdurl" value="" /><!--第三方系统备注字段-->
            <input type="hidden" name="errorurl" value="" /><!--第三方系统备注字段-->
        </form>
        <!--<a href="#" class="btn green-btn pay-btn" data-order_id="{BEESCRM:$order_id}">立即付款</a>-->
    </div>
    <a href="#" class="btn text-center font-16">确认支付</a>
    <div class="hint  gray ">
        <p class="red">温馨提示：</p>
        <p class="red">请保护好您自己一卡通的账号安全！</p>
    </div>
</div>
<include file="commonJs" />
</body>
<script>
    var height = $(window).height();
    $('.wraper').css('minHeight', height);

    //点击获取验证码
    var verifyTag = true;
    $('.content-list').on('click', '.send', function (e) {
        e.preventDefault();
        if (verifyTag)
            getCode(this);
        else
            return;
    });

    // 发送验证码
    function getCode(elem) {
        var data = {};
        data.mobile = $('#mobile').val();
        var one_card_id = "{BEESCRM:$one_card_id}";
        var verify = /^(?:13\d|15\d|18\d|17\d|14\d)\d{5}(\d{3}|\*{3})$/;
        if (!verify.test(data.mobile)) {
            fm.alert('请输入正确的手机号码');
            return false;
        }else{
            $.ajax({
                url:"/base/OneCard/sendText?one_card_id="+one_card_id,
                type:'POST',
                dataType:'json',
                data:data,
                async: false,
                success:function (res) {
                    if(res.status == 'S'){
                        timeCountDown(elem);
                    } else {
                        fm.alert(res.message);
                    }
                }
            });
            timeCountDown(elem);
        }
    }

    // 验证倒计时
    function timeCountDown(elem, seconds) {
        verifyTag = false;
        if (typeof seconds == undefined || seconds == null) seconds = 60;
        setTimeout(function () {
            if (seconds > 0) {
                seconds--;
                $(elem).text('已发送 ' + seconds + 's').addClass('time');
                timeCountDown(elem, seconds);
            } else {
                $(elem).removeClass('time').text('获取验证码');
                verifyTag = true;
            }
        }, 1000);
    }

    //绑定
    $('.btn').click(function () {
        var username = $("#username").val();
        var account = $("#account").val();
        var password = $("#password").val();

        if (!username) {
            fm.alert('请输入姓名');
            return false;
        }
        if (!account) {
            fm.alert('请输入一卡通账号');
            return false;
        }
        if (!password) {
            fm.alert('请输入密码');
            return false;
        }
        /*$("input[name=tranamt]").val("{BEESCRM:$tranamt}");
        $("input[name=account]").val(account);
        $("input[name=sno]").val(account);
        $("input[name=toaccount]").val("{BEESCRM:$toaccount}");
        $("input[name=thirdsystem]").val("{BEESCRM:$thirdsystem}");
        $("input[name=thirdorderid]").val("{BEESCRM:$thirdorderid}");
        $("input[name=ordertype]").val("{BEESCRM:$ordertype}");
        $("input[name=sign]").val("{BEESCRM:$sign}");
        $("input[name=orderdesc]").val("{BEESCRM:$orderdesc}");
        $("input[name=praram1]").val("{BEESCRM:$praram1}");
        $("input[name=thirdurl]").val("{BEESCRM:$thirdurl}");
        $("input[name=errorurl]").val("{BEESCRM:$errorurl}");
        $("#form_campuscard").attr("action","{BEESCRM:$interface_url}");
        $("#form_campuscard").submit();*/
            var json = {};
            json.restaurant_id = $("#restaurant_id").val();
            json.res_id = $("#res_id").val();
            json.iPad_id = $("#iPad_id").val();
            json.order_id = $("#order_id").val();
            json.account = $("#account").val();
            $.ajax({
                url: '/restaurantstyy/ZduRestaurantApi/oneCardPayByAccount',
                type: "POST",
                dataType: "json",
                data: json,
                success: function (data) {
                    if(data.status == 'S'){
                        $("input[name=tranamt]").val(data.data['tranamt']);
                        $("input[name=account]").val(data.data['account']);
                        $("input[name=sno]").val(data.data['sno']);
                        $("input[name=toaccount]").val(data.data['toaccount']);
                        $("input[name=thirdsystem]").val(data.data['thirdsystem']);
                        $("input[name=thirdorderid]").val(data.data['thirdorderid']);
                        $("input[name=ordertype]").val(data.data['ordertype']);
                        $("input[name=sign]").val(data.data['sign']);
                        $("input[name=orderdesc]").val(data.data['orderdesc']);
                        $("input[name=praram1]").val(data.data['praram1']);
                        $("input[name=thirdurl]").val(data.data['thirdurl']);
                        $("input[name=errorurl]").val(data.data['errorurl']);
                        $("#form_campuscard").attr("action",data.data['interface_url']);
                        $("#form_campuscard").submit();
                    } else {
                        fm.alert(data.message, "", 3, "");
                    }
                }
            });
    });


    /*function redirect() {
        window.location.href = window.sessionStorage.getItem("local_url");
        window.sessionStorage.setItem("local_url",null);
    }*/
</script>
</html>